package com.example.telesys.config;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 配置Sentinel的授权规则中 自定义来源处理的配置类
 * 比如A服务与B服务都要调用C服务
 * 假设A服务在调用C服务时 才符合白名单或者黑名单上的规则
 * 因此只会对A服务生效
 */
//@Component
public class RequestOriginParserDefinition implements RequestOriginParser {
    @Override
    public String parseOrigin(HttpServletRequest request) {
        String serviceName = request.getParameter("serviceName");
        if(StringUtil.isNullOrEmpty(serviceName))
            throw new RuntimeException();
        return serviceName;
    }
}
